﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Wicresoft.SMS.Data;
using Wicresoft.SMS.Common;

namespace Wicresoft.SMS.Gateway.Host
{
    public class SendReminderTask : Task
    {
        private ReminderService _reminder;
        private IServiceConfigProvider _configProvider;

        public SendReminderTask(IServiceConfigProvider configProvider, ReminderService reminder)
        {
            _configProvider = configProvider;
            _reminder = reminder;
        }

        protected override int TaskEnable
        {
            get
            {
                return _configProvider.SendReminderTaskEnable;
            }
            set
            {
                TaskEnable = value;
            }
        }
        protected override int TaskSpan
        {
            get
            {
                return _configProvider.SendReminderTaskSpan;
            }
            set
            {
                TaskSpan = value;
            }
        }

        protected override void ExecuteCore()
        {
            DBLog.Debug("Entering SendReminderTask Core");
            while (_scanAble && TaskEnable == 1)
            {
                _reminder.SendReminder();
                DBLog.Debug("SendReminderTask : after send");
                System.Threading.Thread.Sleep(
                    TaskSpan < GlobalFactory.TaskSpanBorder ? GlobalFactory.TaskSpanBorder : _configProvider.SendMsgTaskSpan);
            }
        }

    }
}
